import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/dashboard'
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: () => import('@/views/Dashboard.vue'),
    meta: {
      title: '系统状态',
      icon: 'Monitor'
    }
  },
  {
    path: '/mqtt-config',
    name: 'MqttConfig',
    component: () => import('@/views/MqttConfig.vue'),
    meta: {
      title: 'MQTT配置',
      icon: 'Connection'
    }
  },
  {
    path: '/modbus-config',
    name: 'ModbusConfig',
    component: () => import('@/views/ModbusConfig.vue'),
    meta: {
      title: 'Modbus配置',
      icon: 'Cpu'
    }
  },
  {
    path: '/device-config',
    name: 'DeviceConfig',
    component: () => import('@/views/DeviceConfig.vue'),
    meta: {
      title: '设备配置',
      icon: 'Setting'
    }
  },
  {
    path: '/protocol-config',
    name: 'ProtocolConfig',
    component: () => import('@/views/ProtocolConfig.vue'),
    meta: {
      title: '协议配置',
      icon: 'Document'
    }
  },
  {
    path: '/dispatch-logic',
    name: 'DispatchLogic',
    component: () => import('@/views/DispatchLogic.vue'),
    meta: {
      title: '调度逻辑',
      icon: 'DataLine'
    }
  },
  {
    path: '/system-config',
    name: 'SystemConfig',
    component: () => import('@/views/SystemConfig.vue'),
    meta: {
      title: '系统配置',
      icon: 'Tools'
    }
  },
  {
    path: '/logs',
    name: 'Logs',
    component: () => import('@/views/Logs.vue'),
    meta: {
      title: '系统日志',
      icon: 'List'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = `${to.meta.title} - EMS网关管理`
  }
  next()
})

export default router